<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            border: 1px solid;
            margin-top: 10px;
            cursor: pointer;
            width: 100px;
        }
        
        .on {
            color: red;
        }
    </style>
</head>

<body>
    <ul id="app" onclick="clickLi();">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>

    <script>
        function clickLi() {
            // console.log(event.target);
            var target = event.target;
            console.log(target);
            if (target.nodeName !== 'LI') return false;
            // 其他的li清除颜色
            var $li = document.querySelector('.on');
            if ($li) {
                $li.className = ''
            }
            // 被点击的li改变颜色
            target.className = 'on';
        }
    </script>
</body>

</html>